﻿using System;
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace zhangkong
{
    public partial class HelpPage : PhoneApplicationPage
    {
        public HelpPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            LoadBackgroundImage();
        }

        private void LoadBackgroundImage()
        {
            try
            {
                BitmapImage img = new BitmapImage();
                string filePath = App.BackgroundImageUri;
                using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (iso.FileExists(filePath))
                    {
                        using (var source = iso.OpenFile(filePath, FileMode.Open, FileAccess.Read))
                        {
                            img.SetSource(source);
                        }
                        ImageBrush imgBrush = new ImageBrush();
                        imgBrush.ImageSource = img;
                        LayoutRoot.Background = imgBrush;
                    }
                    else
                    {
                        MessageBox.Show("亲，没能找到背景图片！请卸载后重新安装应用！");
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\nError In\nCoursePgae.xaml\n反馈有奖");
            }

        }
    }
}